package com.infraassets.utils
{
	import com.adobe.images.JPGEncoder;
	
	import flash.display.BitmapData;
	import flash.utils.ByteArray;
	
	import mx.graphics.codec.JPEGEncoder;
	import mx.graphics.codec.PNGEncoder;
	
	import spark.components.DropDownList;
	
	/**
	 * Author      :Khamsany Misran
	 * Date        :21 Dec 2010
	 * Description :This utilities class is collection of common utils in isewer system
	 *              the code will frequently update.
	 **/
	public class UtilsInfra
	{
		
		public function UtilsInfra()
		{
		}
		
		//Misc Utilities
		public static function generateFileNameByTimeStamp(seperator:String = "_"):String {
			var strDate:Date = new Date;
			var fileName:String = strDate.getFullYear().toString() + seperator + (strDate.getMonth()+1) + seperator + strDate.getMonth() + seperator +
				strDate.getHours() + seperator + strDate.getMinutes() + seperator + strDate.getSeconds();
			return fileName;
		}
		//ComboBox Utilities
		public static function setComboIndexbyId(dropDownList:DropDownList, indexId:int):int {
			var myIndex:int;
			for (var i:int = 0; i < dropDownList.dataProvider.length; i++) {
				if(dropDownList.dataProvider[i].data == indexId) {
					myIndex = i;
					return myIndex;
				} else {
					myIndex = -1;
				}
			}
			return myIndex;
		} 
			
		//Image Utilities
		public static function encodeJPEG(bitmap:BitmapData, quality:int = 80):ByteArray {
			var jpegEncoder:JPEGEncoder = new JPEGEncoder(quality);
			var encodedBytes:ByteArray = jpegEncoder.encode(bitmap);
			return encodedBytes;
		}
		
		public static function encodeJPG(bitmap:BitmapData, quality:int = 80):ByteArray {
			var jpgEncoder:JPGEncoder = new JPGEncoder(quality);
			var encodedBytes:ByteArray = jpgEncoder.encode(bitmap);
			return encodedBytes;
		}
		
		public static function encodePNG(bitmap:BitmapData):ByteArray {
			var pngEncoder:PNGEncoder = new PNGEncoder;
			var encodedBytes:ByteArray = pngEncoder.encode(bitmap);
			return encodedBytes;

		}
		
	}
}